/**************************************************************************//**
 * @file    Parabola.c
 * @author  İsmail SEZEN (email: sezenismail@gmail.com)
 * @date    02-08-2009
 *
 * @note This is part of siklon project. (Siklon.c)
 *
 * <b>Description</b>
 *
 * This is file contains functions to calculate the result of a parabloic function.\n
 *
 * Copyright (C) 2009 İsmail SEZEN
 *
 * <b>License</b>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *****************************************************************************/

/*Macros*///{
/*! @brief Calculates the coefficient due to i,j and k values */
#define coeff(i,j,k) (y##i / ((x##i-x##j) * (x##i-x##k)))
/*! @brief Represents the formula unit of a parabola and calculates it's value due to i,j and k. */
#define A(i,j,k) (a##i*(x-x##j)*(x-x##k))
//}

/*! @name Coefficient variables of the Second degree Polynomial
 *  These variables has initial values and may be changed in the \ref calc_Parabol_coef function by coeff(i,j,k) macro.
 */
//@{//{
double a0=0.0,a1=0.0,a2=0.0;
//}//@}

/*! @name Initial values of relative x location coordinates
 *  These variables are set according to grid resolution. The NC files that we use
 *  in this program has 2.5 x 2.5 grid resolution. So, if middle point location
 *  value of a grid is 0(zero), Left grid point location is -2.5 and right grid
 *  location point is 2.5. If we work on another grid resolution. This values must
 *  be changed according to this. For example:
 *  @code
 *  //if resolution is 1.25 x 1.25
 *  double x0=-1.25,x1=0.0,x2=1.25;
 *  @endcode
 *  @note These variables are used by coeff(i,j,k) macro to calculate the coefficients of second degree parabola.
 */
//@{//{
double x0=-2.5,x1=0.0,x2=2.5;
//}//@}

/*! @brief Calculates 3 coenfficients of a second degree polynomial.
 *  @param[in] y0 This is the f function result corresponding to x0.
 *  @param[in] y1 This is the f function result corresponding to x1.
 *  @param[in] y2 This is the f function result corresponding to x2.
 *  @return void */
void f_parabola_calc_coefficients(double y0, double y1, double y2) {
	a0 = coeff(0,1,2);
	a1 = coeff(1,0,2);
	a2 = coeff(2,0,1);
}

/*! @brief Parabola function.
 *
 *  This is parabola functon \f$ y=ax^2+bx+c \f$
 *  @param[in] x This is the variable of the function.
 *  @return result of the parabola function */
double f_parabola(double x) {return A(0,1,2) + A(1,0,2) + A(2,0,1);}
